/*
 * Copyright (c) 2012-2014, EpicSaaS Yuan Xin technology Co., Ltd.
 * 
 * All rights reserved.
 */
package com.epicsaas.app.ksdapp.controller.phone;

import com.epicpaas.sdk.core.api.logging.Logger;
import com.epicpaas.sdk.core.api.logging.LoggerFactory;
import com.epicpaas.sdk.core.api.ServiceResult;
import com.epicsaas.framework.util.DateTimeUtils;
import com.epicsaas.app.ksdapp.common.MVCViewName;
import com.epicsaas.app.ksdapp.entity.gen.CategoryCriteria;
import com.epicsaas.app.ksdapp.entity.gen.ItemCriteria;
import com.epicsaas.app.ksdapp.entity.gen.ItemImgCriteria;
import com.epicsaas.app.ksdapp.entity.gen.ShopCriteria;
import com.epicsaas.app.ksdapp.entity.gen.ShopItemCriteria;
import com.epicsaas.app.ksdapp.entity.gen.ShopUserCriteria;
import com.epicsaas.app.ksdapp.service.ICategoryService;
import com.epicsaas.app.ksdapp.service.IItemImgService;
import com.epicsaas.app.ksdapp.service.IItemService;
import com.epicsaas.app.ksdapp.service.IProductService;
import com.epicsaas.app.ksdapp.service.IShopItemService;
import com.epicsaas.app.ksdapp.service.IShopService;
import com.epicsaas.app.ksdapp.service.IShopUserService;
import com.epicsaas.app.ksdapp.service.ItemService;
import com.epicsaas.app.ksdapp.service.ShopItemService;
import com.epicsaas.app.ksdapp.android.bean.Brand;
import com.epicsaas.app.ksdapp.android.bean.Brand.Type;
import com.epicsaas.app.ksdapp.android.bean.Condition;
import com.epicsaas.app.ksdapp.android.bean.MainTopAdvertisement.AdServing;
import com.epicsaas.app.ksdapp.android.bean.MainTopAdvertisement.AdServing.AdMaterial;
import com.epicsaas.app.ksdapp.android.bean.Product.SkuProduct;
import com.epicsaas.app.ksdapp.android.bean.Product.SpecificationValues;
import com.epicsaas.app.ksdapp.android.bean.Product.Specifications;
import com.epicsaas.app.ksdapp.android.bean.BrandRecommend;
import com.epicsaas.app.ksdapp.android.bean.MainTopAdvertisement;
import com.epicsaas.app.ksdapp.android.bean.PageEntity;
import com.epicsaas.app.ksdapp.android.bean.Product;
import com.epicsaas.app.ksdapp.android.bean.ProductBundle;
import com.epicsaas.app.ksdapp.android.bean.ProductCategory;
import com.epicsaas.app.ksdapp.android.bean.ProductImage;
import com.epicsaas.app.ksdapp.appobject.CategoryAO;
import com.epicsaas.app.ksdapp.appobject.ItemAO;
import com.epicsaas.app.ksdapp.appobject.ItemImgAO;
import com.epicsaas.app.ksdapp.appobject.ShopAO;
import com.epicsaas.app.ksdapp.appobject.ShopItemAO;
import com.epicsaas.app.ksdapp.appobject.ShopUserAO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Product控制器。商品处理
 * 
 */
@Controller
@RequestMapping(value = "/phone/product")
public class ProductController {

    private static Logger LOG = LoggerFactory.getLogger(ProductController.class);

    @Resource
    private ICategoryService categoryService;

    @Resource
    private IShopService shopService;

    @Resource
    private IShopUserService shopUserService;

    @Resource
    private IShopItemService shopItemService;

    @Resource
    private IItemService itemService;

    @Resource
    private IItemImgService itemImgService;

    @Resource
    private IProductService productService;

    @RequestMapping(value = "", method = RequestMethod.GET)
    @ResponseBody
    public Object getAll(Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        ServiceResult<Object> ret = new ServiceResult<Object>();
        ret.setData(DateTimeUtils.formateDateToStr(new Date(), DateTimeUtils.FORMAT_YMD_HMS));
        return ret;
    }

    /**
     * 获取我的顶级空时店的广告
     * 
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/advertisement", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object list(Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        //将当前时间传到前端
        model.addAttribute("currentTime", DateTimeUtils.formateDateToStr(new Date(), DateTimeUtils.FORMAT_YMD_HMS));
        //将当前运用名称传到前端

        MainTopAdvertisement bean = new MainTopAdvertisement();
        List<AdServing> activeServings = new ArrayList<AdServing>();
        AdServing ad1 = bean.new AdServing();
        ad1.setId(1);
        ad1.setType("");
        AdServing.AdMaterial adMaterial = ad1.new AdMaterial();
        adMaterial.setId(1);
        adMaterial.setPath("http://ttimg0.tuicool.com/11000072.png");
        adMaterial.setUrl("");
        ad1.setAdMaterial(adMaterial);

        AdServing ad2 = bean.new AdServing();
        ad2.setId(2);
        ad2.setType("");

        AdServing.AdMaterial adMaterial2 = ad1.new AdMaterial();
        adMaterial2.setId(2);
        adMaterial2.setPath("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1416835233_2304.JPG");
        adMaterial2.setUrl("");
        ad2.setAdMaterial(adMaterial2);

        AdServing ad3 = bean.new AdServing();
        ad3.setId(3);
        ad3.setType("");
        AdServing.AdMaterial adMaterial3 = ad1.new AdMaterial();
        adMaterial3.setId(3);
        adMaterial3.setPath("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1416835233_2304.JPG");
        adMaterial3.setUrl("");
        ad3.setAdMaterial(adMaterial3);

        AdServing ad4 = bean.new AdServing();
        ad4.setId(4);
        ad4.setType("");
        AdServing.AdMaterial adMaterial4 = ad1.new AdMaterial();
        adMaterial4.setId(4);
        adMaterial4.setPath("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1416835233_2304.JPG");
        adMaterial4.setUrl("");
        ad4.setAdMaterial(adMaterial4);

        activeServings.add(ad1);
        activeServings.add(ad2);
        activeServings.add(ad3);
        activeServings.add(ad4);
        bean.setActiveServings(activeServings);
        return bean;
    }

    /**
     * 
     * @param shopId 零售商Id
     * @param pageNumber
     * @param pageSize
     * @param orderProperty
     * @param orderDirection
     * @param model
     * @param request
     * @return
     */

    @RequestMapping(value = "/products", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object products(String shopid, String userid, int pageNumber, int pageSize, String orderProperty,
            String orderDirection, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        List<Product> listProduct = new ArrayList<Product>();

        listProduct = productService.getProductsByShopidAndUid(shopid, userid, null);

        /**
         *         {
            "id": 350,
            "name": "新款无袖双肩婚纱礼服 新娘结婚礼服镂空蕾丝 甜美公主",
            "image": "http://221.178.139.194:13780/upload/image/1219078b-fb97-4f7d-960c-5e5a71b7e6e6.jpg",
            "price": 1200,
            "referencePrice": 1300,
            "discount": 0.92,
            "isTop": false,
            "preferentialType": "featuredDeal",
            "startTime": 1433990464000,
            "endTime": 1435633200000,
            "sales": 0,
            "share": 0,
            "itemId": 579,
            "path": "http://server:8080/hsc/product/content/201506/350.html",
            "isList": false,
            "productCategory": {
                "id": 4,
                "name": "白纱"
        				            },
        				            "brand": {
        				                "id": 3,
        				                "name": "索菲娅公主"
        				            }
        				   }
         */

        Calendar c = Calendar.getInstance();
        //现在的时间(单位：毫秒) 
        long nowMills = c.getTimeInMillis();
        //第二个参数是设置月的，月是基于0的 
        //arg list:year,month,day,hour,minute,second 
        c.set(2015, 9, 1, 0, 0, 0);
        long endMills = c.getTimeInMillis();

        pageEntity.setContent(listProduct);
        pageEntity.setEndDate(nowMills + 3600 * 1000 * 10); //10小时
        pageEntity.setNowDate(nowMills);
        pageEntity.setTotal(listProduct.size());
        pageEntity.setPageNumber(1);
        pageEntity.setTotalPages(1);
        pageEntity.setPageSize(10);

        long l = pageEntity.getEndDate() - pageEntity.getNowDate();
        System.out.println(l);

        return pageEntity;
    }

    @RequestMapping(value = "/category", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object category(String shopid, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        List<ProductCategory> listProductCategory = new ArrayList<ProductCategory>();

        //获取树目录
        CategoryCriteria example = new CategoryCriteria();
        example.createCriteria().andLevelEqualTo(2).andIsShowNotEqualTo(1); //等于1 不显示
        ServiceResult<List<CategoryAO>> listCategoryAO = categoryService.selectByCriteria(example);
        if (listCategoryAO.isSucceed() && !CollectionUtils.isEmpty(listCategoryAO.getData())) {
            for (CategoryAO cg : listCategoryAO.getData()) {

                CategoryCriteria childexample = new CategoryCriteria();
                childexample.createCriteria().andLevelEqualTo(4).andIdBetween(cg.getLeft(), cg.getRight())
                        .andIsShowNotEqualTo(1);
                ServiceResult<List<CategoryAO>> childlistCategoryAO = categoryService.selectByCriteria(childexample);
                List<ProductCategory> childlistProductCategory = new ArrayList<ProductCategory>();

                if (childlistCategoryAO.isSucceed() && !CollectionUtils.isEmpty(childlistCategoryAO.getData())) {
                    for (CategoryAO childcg : childlistCategoryAO.getData()) {
                        ProductCategory childpc = new ProductCategory();
                        childpc.set_id(childcg.getId());
                        childpc.setName(childcg.getName());
                        childpc.setAppImage(childcg.getUrl());
                        childpc.setAppLayout(ProductCategory.AppLayout.LIST);
                        childpc.setGrade(1);
                        childlistProductCategory.add(childpc);
                    }
                }

                ProductCategory pc = new ProductCategory();
                pc.set_id(cg.getId());
                pc.setName(cg.getName());
                pc.setAppImage(cg.getUrl());
                pc.setAppLayout(ProductCategory.AppLayout.LIST);
                pc.setGrade(0);
                pc.setChildren(childlistProductCategory);
                listProductCategory.add(pc);
            }
        }
        return listProductCategory;
    }

    @RequestMapping(value = "/category/{id}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object categoryById(int pageNumber, int pageSize, String orderProperty, String orderDirection, Model model,
            HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    /** 11.1 获取9个推荐品牌 */
    @RequestMapping(value = "/brandRecommend", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object listBrand(String quantity, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        List<BrandRecommend> brandRecommendList = new ArrayList<BrandRecommend>();
        //必须返回9个
        for (int i = 0; i < 9; i++) {
            BrandRecommend brandRecommend = new BrandRecommend();
            brandRecommend.setId(i + 1);
            brandRecommend.setName("品牌" + i + 1);
            brandRecommend.setAppImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
            brandRecommendList.add(brandRecommend);
        }

        return brandRecommendList;
    }

    /**
     * 根据查询获取品牌
     * @param condition
     * @param pageNumber
     * @param pageSize
     * @param orderProperty
     * @param orderDirection
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/brand", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object brand(String shopId, int pageNumber, int pageSize, String orderProperty, String orderDirection,
            Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Brand> pageEntity = new PageEntity<Brand>();
        List<Brand> brandList = new ArrayList<Brand>();

        //        Brand b = new Brand();
        //        b.set_id(1);
        //        b.setId(1);
        //        b.setName("xxxx");
        //        b.setType(Type.text);
        //        brandList.add(b);

        pageEntity.setContent(brandList);
        pageEntity.setNowDate(System.currentTimeMillis());
        pageEntity.setTotal(100);
        pageEntity.setTotalPages(2);
        pageEntity.setPageNumber(1);
        pageEntity.setPageSize(2);
        return pageEntity;
    }

    @RequestMapping(value = "/brand/{id}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object brandById(int pageNumber, int pageSize, String orderProperty, String orderDirection, Model model,
            HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    //商品评论 
    @RequestMapping(value = "/reviews/{id}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object reviewsById(int pageNumber, int pageSize, String orderProperty, String orderDirection, Model model,
            HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    @RequestMapping(value = "/relatedProducts/{id}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object relatedProductsById(int pageNumber, int pageSize, String orderProperty, String orderDirection,
            Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    @RequestMapping(value = "/suggest", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object suggest(String keyword, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    /**
     * 获取检索的关键字
     * @param pageNumber
     * @param pageSize
     * @param orderProperty
     * @param orderDirection
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/keyWords", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object keyWords(Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        List<String> pageEntity = new ArrayList<String>();
        pageEntity.add("喜");
        return pageEntity;
    }

    @RequestMapping(value = "/condition", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object condition(String shopid, String userid, String keyword, String category, Model model,
            HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        List<Condition> list = new ArrayList<Condition>();
        Condition c = new Condition();
        c.setId("1");
        c.setName("最新");
        c.setOptionid(1);
        List<String> options = new ArrayList<String>();
        options.add("最新");
        c.setOptions(options);
        list.add(c);
        return list;
    }

    /**
     * 模糊搜索 某家商品
     * @param shopid
     * @param keyword
     * @param category
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/fuzzy", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public PageEntity<Product> fuzzy(String shopid, String userid, String keyword, String category, Model model,
            HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        List<Product> listProduct = new ArrayList<Product>();

        listProduct = productService.getProductsByShopidAndUid(shopid, userid, keyword);

        pageEntity.setContent(listProduct);
        //        pageEntity.setEndDate(nowMills + 3600 * 1000 * 10); //10小时
        //        pageEntity.setNowDate(nowMills);
        pageEntity.setTotal(listProduct.size());
        pageEntity.setPageNumber(1);
        pageEntity.setTotalPages(1);
        pageEntity.setPageSize(10);

        long l = pageEntity.getEndDate() - pageEntity.getNowDate();
        System.out.println(l);

        return pageEntity;

    }

    @RequestMapping(value = "/featured_deal/random", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object featured_deal_random(String keyword, String category, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());

        PageEntity<Product> pageEntity = new PageEntity<Product>();

        return pageEntity;
    }

    /**
     * 
     * @param type   //商品类型   
     * @param pageNumber //第几页
     * @param pageSize //每页大小
     * @param orderProperty  //排序字段
     * @param orderDirection   //asc desc
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object list(String type, int pageNumber, int pageSize, String orderProperty, String orderDirection,
            Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        //type 特卖
        PageEntity<Product> pageEntity = new PageEntity<Product>();

        List<Product> listProduct = new ArrayList<Product>();

        /**
         *         {
            "id": 350,
            "name": "新款无袖双肩婚纱礼服 新娘结婚礼服镂空蕾丝 甜美公主",
            "image": "http://221.178.139.194:13780/upload/image/1219078b-fb97-4f7d-960c-5e5a71b7e6e6.jpg",
            "price": 1200,
            "referencePrice": 1300,
            "discount": 0.92,
            "isTop": false,
            "preferentialType": "featuredDeal",
            "startTime": 1433990464000,
            "endTime": 1435633200000,
            "sales": 0,
            "share": 0,
            "itemId": 579,
            "path": "http://server:8080/hsc/product/content/201506/350.html",
            "isList": false,
            "productCategory": {
                "id": 4,
                "name": "白纱"
        				            },
        				            "brand": {
        				                "id": 3,
        				                "name": "索菲娅公主"
        				            }
        				   }
         */

        Product product = new Product();
        product.setId(1);
        product.setName("昆仑玉红枣 测试");
        product.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        product.setReferencePrice(1300);
        //////product.setPrice(1200);
        product.setDiscount(new BigDecimal(0.82));
        product.setTop(false);
        product.setPreferentialType("featuredDeal");
        product.setStartTime(System.currentTimeMillis());
        product.setEndTime(System.currentTimeMillis() + 1000);
        product.setSales(100);
        listProduct.add(product);

        Product product1 = new Product();
        product1.setId(2);
        product1.setName("天喜高端茶漏杯");
        product1.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1416835233_2304.JPG");
        product1.setReferencePrice(1300);
        //product1.setPrice(1200);
        product1.setDiscount(new BigDecimal(0.82));
        product1.setTop(false);
        product1.setPreferentialType("featuredDeal");
        product1.setStartTime(System.currentTimeMillis());
        product1.setEndTime(System.currentTimeMillis() + 1000);
        product1.setSales(100);
        listProduct.add(product1);

        Product product2 = new Product();
        product2.setId(2);
        product2.setName("昆仑玉红枣");
        product2.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        product2.setReferencePrice(1300);
        //product2.setPrice(1200);
        product2.setDiscount(new BigDecimal(0.82));
        product2.setTop(false);
        product2.setPreferentialType("featuredDeal");
        product2.setStartTime(System.currentTimeMillis());
        product2.setEndTime(System.currentTimeMillis() + 1000);
        product2.setSales(100);
        listProduct.add(product2);

        Calendar c = Calendar.getInstance();
        //现在的时间(单位：毫秒) 
        long nowMills = c.getTimeInMillis();
        //第二个参数是设置月的，月是基于0的 
        //arg list:year,month,day,hour,minute,second 
        c.set(2015, 9, 1, 0, 0, 0);
        long endMills = c.getTimeInMillis();

        pageEntity.setContent(listProduct);
        pageEntity.setEndDate(nowMills + 3600 * 1000 * 10); //10小时
        pageEntity.setNowDate(nowMills);
        pageEntity.setTotal(1);
        pageEntity.setPageNumber(1);
        pageEntity.setTotalPages(1);
        pageEntity.setPageSize(10);

        long l = pageEntity.getEndDate() - pageEntity.getNowDate();
        System.out.println(l);

        return pageEntity;
    }

    /**
     * 团购
     * @param quantity 显示的团购商品数量
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/group_buying", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object group_buying(int quantity, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        List<Product> listProduct = new ArrayList<Product>();

        Product product = new Product();
        product.setId(1);
        product.setName("昆仑玉红枣 测试");
        product.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        product.setReferencePrice(1300);
        //////product.setPrice(1200);
        product.setDiscount(new BigDecimal(0.82));
        product.setTop(false);
        product.setPreferentialType("featuredDeal");
        product.setStartTime(System.currentTimeMillis());
        product.setEndTime(System.currentTimeMillis() + 1000);
        product.setSales(100);
        listProduct.add(product);

        Product product1 = new Product();
        product1.setId(2);
        product1.setName("天喜高端茶漏杯");
        product1.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1416835233_2304.JPG");
        product1.setReferencePrice(1300);
        //product1.setPrice(1200);
        product1.setDiscount(new BigDecimal(0.82));
        product1.setTop(false);
        product1.setPreferentialType("featuredDeal");
        product1.setStartTime(System.currentTimeMillis());
        product1.setEndTime(System.currentTimeMillis() + 1000);
        product1.setSales(100);
        listProduct.add(product1);

        Product product2 = new Product();
        product2.setId(2);
        product2.setName("昆仑玉红枣");
        product2.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        product2.setReferencePrice(1300);
        //product2.setPrice(1200);
        product2.setDiscount(new BigDecimal(0.82));
        product2.setTop(false);
        product2.setPreferentialType("featuredDeal");
        product2.setStartTime(System.currentTimeMillis());
        product2.setEndTime(System.currentTimeMillis() + 1000);
        product2.setSales(100);
        listProduct.add(product2);

        return listProduct;
    }

    /**
     * 单品推荐
     * @param type   //商品类型   
     * @param pageNumber //第几页
     * @param pageSize //每页大小
     * @param orderProperty  //排序字段
     * @param orderDirection   //asc desc
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/recommend", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object recommend(String userid, int pageNumber, int pageSize, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        //type 特卖
        PageEntity<Product> pageEntity = new PageEntity<Product>();

        List<Product> listProduct = new ArrayList<Product>();

        listProduct = productService.getRecommendsByUid(String.valueOf(userid));

        /**
         *         {
            "id": 350,
            "name": "新款无袖双肩婚纱礼服 新娘结婚礼服镂空蕾丝 甜美公主",
            "image": "http://221.178.139.194:13780/upload/image/1219078b-fb97-4f7d-960c-5e5a71b7e6e6.jpg",
            "price": 1200,
            "referencePrice": 1300,
            "discount": 0.92,
            "isTop": false,
            "preferentialType": "featuredDeal",
            "startTime": 1433990464000,
            "endTime": 1435633200000,
            "sales": 0,
            "share": 0,
            "itemId": 579,
            "path": "http://server:8080/hsc/product/content/201506/350.html",
            "isList": false,
            "productCategory": {
                "id": 4,
                "name": "白纱"
        				            },
        				            "brand": {
        				                "id": 3,
        				                "name": "索菲娅公主"
        				            }
        				   }
         */
        pageEntity.setContent(listProduct);
        pageEntity.setNowDate(System.currentTimeMillis());
        pageEntity.setTotal(listProduct.size());
        pageEntity.setPageNumber(1);
        pageEntity.setTotalPages(1);
        pageEntity.setPageSize(100);
        return pageEntity;
    }

    @RequestMapping(value = "/view/{dataId}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object viewById(String userid, @PathVariable String dataId, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        Product product = new Product();
        //        product.setId(1);
        //        product.setDiscount(new BigDecimal(9));
        //        product.setHits(100);
        //
        //        product.setName("新款 昆仑玉红枣 balabala");
        //        product.setImage("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        //        product.setReferencePrice(1300);
        //        //////product.setPrice(1200);
        //        product.setDiscount(new BigDecimal(9));
        //        product.setTop(false);
        //        product.setPreferentialType("featuredDeal");
        //        product.setStartTime(1433990464000L);
        //        product.setEndTime(1435633200000L);
        //        product.setSales(100);
        //        product.setFavoriteCount(111);
        //        product.setReviewCount(222);
        //        product.setHits(1222);
        //        product.setWeight(11);
        //        product.setPreferentialType("太她玛的优惠啦");
        //
        //        List<ProductImage> productImages = new ArrayList<ProductImage>();
        //        ProductImage productImage1 = new ProductImage();
        //        productImage1.setOrder(1);
        //        productImage1.setTitle("balabala1");
        //        productImage1.setSource("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        //        productImages.add(productImage1);
        //
        //        ProductImage productImage2 = new ProductImage();
        //        productImage2.setOrder(2);
        //        productImage2.setTitle("balabala2");
        //        productImage2.setSource("http://mmpu-uploads.stor.sinaapp.com/images/small/file_1414328847_1473.jpg");
        //        productImages.add(productImage2);
        //        product.setProductImages(productImages);
        //
        //        List<ProductBundle> bundles = new ArrayList<ProductBundle>();
        //        ProductBundle productBundle1 = new ProductBundle();
        //        productBundle1.setId(1);
        //        productBundle1.setName("名字 吧啦吧啦");
        //        productBundle1.setMarketPrice(1300.21f);
        //        productBundle1.setPrice(1200.00f);
        //        productBundle1.setShow(true);
        //        bundles.add(productBundle1);
        //        product.setBundles(bundles);
        //
        //        product.setFavorite(true);
        //        product.setProductId(1);
        //
        //        List<Product.Specifications> specifications = new ArrayList<Product.Specifications>();
        //        Product.Specifications specification1 = new Product.Specifications(); //说明 specification
        //        specification1.setId(1);
        //        specification1.setName("商品说明");
        //        List<Product.SpecificationValues> specificationValues = new ArrayList<Product.SpecificationValues>();
        //        Product.SpecificationValues specificationValue1 = new Product.SpecificationValues();
        //        specificationValue1.setId(1);
        //        specificationValue1.setName("sdadsadsa111");
        //        specificationValues.add(specificationValue1);
        //
        //        Product.SpecificationValues specificationValue2 = new Product.SpecificationValues();
        //        specificationValue2.setId(2);
        //        specificationValue2.setName("sdadsadsa112");
        //        specificationValues.add(specificationValue2);
        //        specification1.setSpecificationValues(specificationValues);
        //
        //        specifications.add(specification1);
        //        product.setSpecifications(specifications);

        List<Product> ret = productService.getProductsByUidAndProductid(userid, dataId);
        if (ret != null && ret.size() > 0) {
            product = ret.get(0);

            List<ProductImage> productImages = new ArrayList<ProductImage>();

            ItemImgCriteria example = new ItemImgCriteria();
            example.createCriteria().andItemIdEqualTo(Integer.parseInt(product.getItemId()));
            ServiceResult<List<ItemImgAO>> retListimg = itemImgService.selectByCriteria(example);
            if (retListimg.isSucceed() && !CollectionUtils.isEmpty(retListimg.getData())) {
                for (ItemImgAO itemImg : retListimg.getData()) {
                    ProductImage productImage = new ProductImage();
                    productImage.setOrder(itemImg.getPosition());
                    productImage.setTitle(itemImg.getPosition() + "");
                    productImage.setSource(itemImg.getPicLarge());
                    productImages.add(productImage);

                }

            }
            product.setProductImages(productImages);

            List<Product.Specifications> specifications = new ArrayList<Product.Specifications>();
            Product.Specifications specification1 = new Product.Specifications(); //说明 specification
            specification1.setId(1);
            specification1.setName("商品说明");
            List<Product.SpecificationValues> specificationValues = new ArrayList<Product.SpecificationValues>();
            Product.SpecificationValues specificationValue1 = new Product.SpecificationValues();
            specificationValue1.setId(1);
            specificationValue1.setName(product.getBrand());
            specificationValues.add(specificationValue1);

            Product.SpecificationValues specificationValue2 = new Product.SpecificationValues();
            specificationValue2.setId(1);
            specificationValue2.setName(product.getDescription());
            specificationValues.add(specificationValue2);

            Product.SpecificationValues specificationValue3 = new Product.SpecificationValues();
            specificationValue3.setId(1);
            specificationValue3.setName(product.getSpec());
            specificationValues.add(specificationValue3);

            specification1.setSpecificationValues(specificationValues);
            specifications.add(specification1);
            product.setSpecifications(specifications);

        }
        return product;
    }

    @RequestMapping(value = "/hit/{dataId}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object hitById(@PathVariable String dataId, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        ServiceResult<Object> ret = new ServiceResult<Object>();
        ret.setData(DateTimeUtils.formateDateToStr(new Date(), DateTimeUtils.FORMAT_YMD_HMS));
        return ret;
    }

    @RequestMapping(value = "/update/{dataId}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object updateById(@PathVariable String dataId, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        ServiceResult<Object> ret = new ServiceResult<Object>();
        ret.setData(DateTimeUtils.formateDateToStr(new Date(), DateTimeUtils.FORMAT_YMD_HMS));
        return ret;
    }

    @RequestMapping(value = "/delete/{dataId}", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object deleteById(@PathVariable String dataId, Model model, HttpServletRequest request) {
        LOG.info("有访问来自，IP: %s USER-AGENT: %s", request.getRemoteAddr(), request.getHeader("user-agent"));
        LOG.info("SessionId %s", request.getSession().getId());
        ServiceResult<Object> ret = new ServiceResult<Object>();
        ret.setData(DateTimeUtils.formateDateToStr(new Date(), DateTimeUtils.FORMAT_YMD_HMS));
        return ret;
    }

}
